<?php

require_once( '/DAL/DbHelper.php');

/**
 * The System Controller providing functions
 */
class Controller_System {

    public $ControllerName = 'Controller_System';
    public $DbHelper = null;

    /**
     * the default Constructor 
     */
    public function __construct() {
        $this->DbHelper = new DbHelper();
    }

    /**
     * Get the RoleList
     * @return type
     */
    public function GetRoleList() {
        $strSql = 'call Proc_Sys_GetConfList(?,?,?)';
        $Parameters = [ 'SystemUI', 'RoleDefinition', 'en'];
        $res = $this->DbHelper->execProcedures($strSql, $Parameters);
        return $res;
    }

    /**
     *  get all the School definition exclude the facualty, here call from a view
     * @return type
     */
    public function GetSchoolList() {
        $res = $this->DbHelper->execSqlStatement("SELECT * FROM View_SchoolList_WithoutFaculty");
        return $res;
    }

    /**
     * return the Application Type
     * @return Application Type 
     */
    public function GetApplicationTypeList() {
        $strSql = 'call func_Sys_GetSystemConfigureKeyValueList(?,?,?)';
        $Parameters = [ 'SystemUI', 'ApplicationType', 'en'];
        $res = $this->DbHelper->execProcedures($strSql, $Parameters);
        return $res;
    }

    /**
     * Return the RefferenceIDType Student or SATAC
     * @return Key Value pair list
     */
    public function GetRefferenceTypeList() {
        $strSql = 'call func_Sys_GetSystemConfigureKeyValueList(?,?,?)';
        $Parameters = [ 'SystemUI', 'RefferenceIDType', 'en'];
        $db = new DbHelper();
        $res = $db->execProcedures($strSql, $Parameters);
        return $res;
    }

    /**
     * Check Login Method
     * @param type $LoginName
     * @return type
     */
    public function ChkLogign($UserId) {
        $strSql = 'call Proc_User_Login(?)';
        $Parameters[] = $UserId;
        $res = $this->DbHelper->execProcedures($strSql, $Parameters);
        return $res;
    }

    // For Advanced search below
    public function searchApplicationSL($referenceTypeID, $referenceUserID) {
        $strSQL = "call Query_Step1(?,?)";
        $parameters[] = $referenceTypeID;
        $parameters[] = $referenceUserID;
        $res = $this->DbHelper->execProcedures($strSQL, $parameters);
        return $res;
    }

    public function searchApplicationAL($applicationID, $handleSchoolID) {
        $strSQL = "call Query_Step2(?,?)";
        $parameters[] = $applicationID;
        $parameters[] = $handleSchoolID;
        $res = $this->DbHelper->execProcedures($strSQL, $parameters);
        return $res;
    }

    /**
     * Get Email Address from the staffs in School[School01|SchoolID02] and Role
     * @param type $handleSchoolIDs
     * @param type $roleID
     * @return  String Array 
     */
    public function getEmailToList($handleSchoolIDs, $roleID) {
        $strSQL = "call Proc_Mail_GetEmailList(?,?)";
        $parameters[] = $handleSchoolIDs;
        $parameters[] = $roleID;
        $res = $this->DbHelper->execProcedures($strSQL, $parameters);
        return $res;
    }

    /**
     * Get Server Notification`
     * Proc_GetServerNotificationByUserID
     * @return type
     */
    public function getServerNotification() {
        $strSQL = "call Proc_GetServerNotificationByUserID(?)";
        $parameters[] = $_SESSION["UserEntity"]->UserID;
        $res = $this->DbHelper->execProcedures($strSQL, $parameters);
        return $res;
    }

}

?>
